<?php $this->load->view('common/head');?>

<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>
                <div class="row">
                    <div class="col-sm-12 widget-container-col ui-sortable" id="widget-container-col-10">
                        <div class="widget-box ui-sortable-handle" id="widget-box-10">
                            <div class="widget-header widget-header-small">
                                <h5 class="widget-title smaller">商家信息</h5>

                                <div class="widget-toolbar no-border">
                                    <ul class="nav nav-tabs" id="myTab">
                                        <li class="<?php if($step == 1){ ?>active<?php } ?>">
                                            <a data-toggle="tab" href="#home" aria-expanded="<?php if($step == 1){ ?>true<?php }else{ ?>false<?php } ?>">商家信息</a>
                                        </li>

                                        <li class="<?php if($step == 2){ ?>active<?php } ?>">
                                            <a data-toggle="tab" href="#profile" aria-expanded="<?php if($step == 2){ ?>true<?php }else{ ?>false<?php } ?>">商家详情</a>
                                        </li>

                                        <li class="<?php if($step == 3){ ?>active<?php } ?>">
                                            <a data-toggle="tab" href="#info" aria-expanded="<?php if($step == 3){ ?>true<?php }else{ ?>false<?php } ?>">商家设置</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>

                            <div class="widget-body">
                                <div class="widget-main padding-6" style="overflow: hidden">
                                    <div class="tab-content">
                                        <div id="home" class="tab-pane <?php if($step == 1){ ?>active<?php } ?>">
                                            <div class="col-xs-12">
                                                <!-- PAGE CONTENT BEGINS -->
                                                <form class="form-horizontal" action="<?php echo site_url(X_URL.'shops/update');?>" method="post" id="from1" >
                                                    <?php if($step == 1){ ?><?php echo csrf_hidden();?><?php } ?>
                                                    <?php if(!isset($shop) && empty($shop['shop_id'])){ ?>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 会员账号 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" id="user_name" name="user_name" class="rcol-xs-10 col-sm-5" value="">
                                                            <input type="hidden" name="shop_id" value="<?php if(!empty($shop)){  echo $shop['shop_id'];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
											<span class="middle">请填写会员账号</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 会员密码 </label>
                                                        <div class="col-sm-9">
                                                            <input type="password" id="user_password" name="user_password" class="rcol-xs-10 col-sm-5" value="">
                                                            <span class="help-inline col-xs-12 col-sm-7">
											<span class="middle">请设置会员密码</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <hr />
                                                    <?php } ?>
                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 商家名称 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="shop_title" class="rcol-xs-10 col-sm-5" value="<?php if(isset($shop)){ echo $shop["shop_title"];}?>">
                                                            <input type="hidden" name="shop_id" value="<?php if(isset($shop)){ echo $shop["shop_id"];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
											<span class="middle">请填写商家名称</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>
                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-4"> 所属频道 </label>
                                                        <div class="col-sm-9">
                                                            <select id="web_category" name="web_category" class="select2">
                                                                <?php foreach ($category as $key =>$val ) { ?>
                                                                    <option value="<?php echo $key;?>" <?php if(isset($shop) && $shop['web_category'] == $key){?>selected="selected"<?php } ?>
                                                                    ><?php echo $val;?></option>
                                                                <?php }?>
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 联系人 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="shop_man" id="shop_man" placeholder="联系人"
                                                                   class="col-xs-10 col-sm-5" value="<?php if(isset($shop)){ echo $shop["shop_man"];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">商家负责人/联系人</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 联系电话 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="shop_tel" id="shop_tel" placeholder="联系电话"
                                                                   class="col-xs-10 col-sm-5" value="<?php if(isset($shop)){ echo $shop["shop_tel"];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">商家负责人/联系人的电话号码</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-2">商家地址</label>
                                                        <div class="col-sm-1">
                                                            <select name="province_id" id="province_id" class="select2" size="1">
                                                                <option value="0">请选择省</option>
                                                                <?php if(isset($province) && !empty($province)){ ?>
                                                                    <?php foreach ($province as $key =>$val ) { ?>
                                                                        <option value="<?php echo $val['area_id'];?>" <?php if(isset($shop) && $shop['shop_province'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name'];?></option>
                                                                    <?php }?>
                                                                <?php }?>
                                                            </select>
                                                        </div>
                                                        <div class="col-sm-1">
                                                            <select name="city_id" id="city_id" class="select2" size="1">
                                                                <option value="0">请选择市</option>
                                                                <?php if(isset($city) && !empty($city)){ ?>
                                                                    <?php foreach ($city as $key =>$val ) { ?>
                                                                        <option value="<?php echo $val['area_id'];?>" <?php if(isset($shop) && $shop['shop_city'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name'];?></option>
                                                                    <?php }?>
                                                                <?php }?>
                                                            </select>
                                                        </div>
                                                        <div class="col-sm-1">
                                                            <select name="district_id" id="district_id" class="select2" size="1">
                                                                <option value="0">请选择区</option>
                                                                <?php if(isset($district) && !empty($district)){ ?>
                                                                    <?php foreach ($district as $key =>$val ) { ?>
                                                                        <option value="<?php echo $val['area_id'];?>" <?php if(isset($shop) && $shop['shop_district'] == $val['area_id']){ ?>selected="selected"<?php } ?> ><?php echo $val['area_name'];?></option>
                                                                    <?php }?>
                                                                <?php }?>
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>
                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label" for="address"></label>
                                                        <div class="col-sm-9">
                                                            <input type="text" id="shop_dress" name="shop_dress" class="col-xs-10 col-sm-5" placeholder="详细地址" value="<?php if(!empty($shop['shop_dress'])){  echo $shop['shop_dress'];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">填写详细地址</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="form-group">
                                                        <label class="col-sm-1 control-label no-padding-right" for="form-field-2"> 经纬度 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="shop_x" id="shop_x" placeholder="经度" readonly
                                                                   class="col-xs-10 col-sm-2" value="<?php if(isset($shop)){ echo $shop['shop_lat'];}?>">
                                                            <input type="text" name="shop_y" id="shop_y" placeholder="纬度" style="margin-left: 60px;" readonly
                                                                   class="col-xs-10 col-sm-2" value="<?php if(isset($shop)){ echo $shop['shop_lng'];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
                                                            <input type="hidden" id="shop_lat" name="shop_lat" value="<?php if(isset($shop)){ echo $shop['shop_lat'];}?>">
                                                            <input type="hidden" id="shop_lng" name="shop_lng" value="<?php if(isset($shop)){ echo $shop['shop_lng'];}?>">
												<span class="middle">填写地址后，自动获取</span>
											</span>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-offset-2 col-md-9">
                                                        <button class="btn btn-info" type="submit" id="subForm1">
                                                            <i class="icon-ok bigger-110"></i>
                                                            提交
                                                        </button>

                                                        &nbsp; &nbsp; &nbsp;
                                                        <button class="btn" type="reset">
                                                            <i class="icon-undo bigger-110"></i>
                                                            重置
                                                        </button>
                                                    </div>


                                                </form>
                                                <!-- PAGE CONTENT ENDS -->
                                            </div><!-- /.col -->
                                        </div>

                                        <div id="profile" class="tab-pane <?php if($step == 2){ ?>active<?php } ?>">
                                            <form class="form-horizontal" action="<?php echo site_url(X_URL.'shops/update2');?>" method="post" id="form2">
                                                <?php if($step == 2){ ?><?php echo csrf_hidden();?><?php } ?>
                                                <input type="hidden" name="shop_id" value="<?php if(!empty($shop_id)){  echo $shop_id;}?>">
                                                <div class="space-4"></div>

                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-8">
                                                        商家详情 </label>
                                                    <div class="col-sm-9">
                                    <textarea name="shop_memo" id="shop_memo"
                                              style="width:85%;height:400px;visibility:hidden;"><?php if(!empty($shop['shop_memo'])){  echo $shop['shop_memo'];}?></textarea>
                                                    </div>
                                                </div>

                                                <div class="space-4"></div>

                                                <div class="col-md-offset-2 col-md-9">
                                                    <button class="btn btn-info" type="submit" id="subForm2">
                                                        <i class="icon-ok bigger-110"></i>
                                                        提交
                                                    </button>

                                                    &nbsp; &nbsp; &nbsp;
                                                    <button class="btn" type="reset">
                                                        <i class="icon-undo bigger-110"></i>
                                                        重置
                                                    </button>
                                                </div>
                                            </form>
                                        </div>

                                        <div id="info" class="tab-pane <?php if($step == 3){ ?>active<?php } ?>">
                                            <form class="form-horizontal" action="<?php echo site_url(X_URL.'shops/update3');?>" method="post" id="form3">
                                                <?php if($step == 3){ ?><?php echo csrf_hidden();?><?php } ?>
                                                <input type="hidden" name="shop_id" value="<?php if(!empty($shop_id)){  echo $shop_id;}?>">
                                                <div class="space-4"></div>

                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-7"> 经营范围 </label>
                                                    <div class="col-sm-9">
                                    <textarea name="shop_about" id="shop_about" placeholder="经营范围" class="col-xs-10 col-sm-5" rows="5"><?php if(!empty($shop['shop_about'])){  echo $shop['shop_about'];}?></textarea>
                                                        <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
                                                    </div>
                                                </div>
                                                <div class="space-4"></div>

                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-6"> 库存警告 </label>
                                                    <div class="col-sm-9">
                                                        <input type="text" name="shop_stock" id="shop_stock" placeholder="库存警告"
                                                               class="col-xs-10 col-sm-5" value="<?php if(!empty($shop['shop_stock'])){  echo $shop['shop_stock'];}?>">
                                                        <span class="help-inline col-xs-12 col-sm-7">
                                                            <span class="middle">库存低于设置值时，会发送通知</span>
                                                        </span>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label no-padding-right" for="form-field-6"> 平台自营商家 </label>
                                                    <div class="col-sm-9">
                                                        <label>
                                                            <input name="self_support" id="self_support" class="ace ace-switch ace-switch-5" type="checkbox" <?php if(isset($shop['self_support']) && $shop['self_support'] == 1 ){ ?>checked="checked"<?php } ?>>
                                                            <span class="lbl"></span>
                                                        </label>
                                                    </div>
                                                </div>
                                                <?php if(isset($shopcategory) && !empty($shopcategory)){ ?>
                                                <div class="form-group">
                                                <label class="col-sm-1 control-label no-padding-right" for="form-field-6"> 商家所属频道 </label>
                                                <div class="col-sm-2">
                                                            <select id="shop_category" name="shop_category" class="select2">
                                                                <option value="0">请选择分类</option>

                                                                
                                                                    <?php foreach ($shopcategory as $key =>$val ) { ?>
                                                                        <option value="<?php echo $val['id'];?>" <?php if(isset($shop) && $shop['shop_category'] == $val['id']){?>selected="selected"<?php } ?>
                                                                        ><?php echo $val['category_name'];?></option>
                                                                    <?php }?>
                                                                
                                                            </select>
                                                        </div>
                                                </div>
                                                <?php }?>
                                                <div class="col-md-offset-2 col-md-9">
                                                    <button class="btn btn-info" type="submit" id="subForm3">
                                                        <i class="icon-ok bigger-110"></i>
                                                        提交
                                                    </button>

                                                    &nbsp; &nbsp; &nbsp;
                                                    <button class="btn" type="reset">
                                                        <i class="icon-undo bigger-110"></i>
                                                        重置
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /section:settings.box -->
                <div class="row">

                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer');?>
</div><!-- /.main-container -->

<?php $this->load->view('common/footerjs');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        $("#tabs").tabs();
        var editor = KindEditor.create('textarea[name="shop_memo"]', {
            uploadJson: baseurl+'index.php/manage/pubfun/editor_upload_img?type=shop&shopid=1',
            fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function () {
                this.sync();
            }
        });
        //填入地址获取经纬度getlocation
        $("#shop_dress").blur(function(){
            var province_id = $("#province_id").val();
            if(province_id != 0){
                var province = $("#province_id option:selected").text();
            }else{
                var province = '';
            }
            var city_id = $("#city_id").val();
            if(city_id != 0){
                var city = $("#city_id option:selected").text();
            }else{
                var city = '';
            }
            if(city == '' || undefined){
                if(province == '' || undefined){
                    alert("请先选择省市");
                    $(this).val("");
                    return false;
                }
            }
            var baddress = $(this).val();
            var address = province+city+baddress;
            $.ajax({
                url:locationurl,
                type:"get",
                data:{'address':address},
                dataType: 'json',
                success: function(data){
                    console.log(data);
                    if(data.status == '1'){
                        $("#shop_lat").val(data.arr.lat);
                        $("#shop_lng").val(data.arr.lng);
                        $("#shop_x").val(data.arr.lat);
                        $("#shop_y").val(data.arr.lng);
                    }else{
                        console.log(data);
                        alert(data.msg);
                    }
                }
            });
        });
        $("#subForm1").click(function () {

            var user_name = $("#user_name").val();
            if (user_name == "") {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "会员账号必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            var user_password = $("#user_password").val();
            if (user_password == "") {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "会员密码必须设置。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            var shop_dress = $("#shop_dress").val();
            if (shop_dress == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "商家地址必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            $("#from1").submit();
        });

        $("#subForm2").click(function () {
            $("#from2").submit();
        });


        $("#subForm3").click(function () {
            var shop_category = $("#shop_category").val();
            if (shop_category == "") {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "商家分类必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return false;
            }
            $("#from3").submit();
        });
    });
</script>
</body>
</html>
